package com.cat.dynamicPlanning;

/**
*   @description https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-ii/
*   @author 曲大人的喵
*   @create 2025/9/7 22:33
*   @since JDK17
*/

public class Solution91 {
    public int maxProfit(int[] prices) {
        int n = prices.length;
        int[][] dp = new int[n][2];
        dp[0][1] = -prices[0];
        for (int i = 1; i < n; i++) {
            dp[i][0] = Math.max(dp[i - 1][0], dp[i - 1][1] + prices[i]);
            dp[i][1] = Math.max(dp[i - 1][1], dp[i - 1][0] - prices[i]);
        }
        return dp[n - 1][0];
    }
}
